Skip to content

ipc4: header: shift notification magic values as unsigned - #11257

Open
tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ipc4/mask_shift/avoid_ub
Open

tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ipc4/mask_shift/avoid_ub

Conversation

@tmleman

@tmleman tmleman commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL and
SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL are defined as (uint32_t)(0xA15A << 16) and (uint32_t)(0xC0C0 << 16). Both literals have bit 15 set, so the int shift produces a value above INT_MAX before the cast is applied, which is undefined behaviour (UBSan: "left shift of 41306 by 16 places cannot be represented in type 'int'", reported from tdfb_ipc4.c). GCC and clang currently wrap, so the resulting values are correct, but the expression is still ill-formed.

Cast to uint32_t before shifting. The macro values are unchanged.

Found by the IPC4 libFuzzer campaign with -fsanitize=undefined.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 09:58
@tmleman
tmleman requested a review from pblaszko as a code owner October 2, 2026 09:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The narrowly scoped change correctly eliminates signed-shift undefined behavior without changing macro values.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes undefined behavior when constructing IPC4 notification event IDs while preserving existing values.

Changes:

  • Casts magic constants to uint32_t before left-shifting.
File Description
src/​include/​ipc4/​header.h Makes IPC4 notification magic-value shifts unsigned.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL and
SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL are defined as
(uint32_t)(0xA15A << 16) and (uint32_t)(0xC0C0 << 16). Both literals
have bit 15 set, so the int shift produces a value above INT_MAX before
the cast is applied, which is undefined behaviour (UBSan: "left shift of
41306 by 16 places cannot be represented in type 'int'", reported from
tdfb_ipc4.c). GCC and clang currently wrap, so the resulting values are
correct, but the expression is still ill-formed.

Cast to uint32_t before shifting. The macro values are unchanged.

Found by the IPC4 libFuzzer campaign with -fsanitize=undefined.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants